package com.weactivity.config;

import com.weactivity.dto.Result;
import com.weactivity.exception.ActivityCreationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 *
 * 服务器异常拦截类
 * 当服务器发生异常时发送服务器异常的信息
 */

@Slf4j
@RestControllerAdvice
public class WebExceptionAdvice {

    @ExceptionHandler(ActivityCreationException.class)
    public Result handleActivityCreationException (ActivityCreationException e){
        log.error(e.toString(),e);
        if (null == e.getData()){
            return Result.fail(e.getMessage());
        }
        return Result.ok(e.getData());

    }

    @ExceptionHandler(RuntimeException.class)
    public Result handleRuntimeException(RuntimeException e){
        log.error(e.toString(),e);
        //待扩展

        return  Result.fail("服务器运行时错误");
    }



}
